package com.qf.joint.controller;
import com.qf.joint.pojo.Jobhunter;
import com.qf.joint.utils.SYS;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

/**
 * @Author Zhy
 * Date on 2020/9/12  23:09
 * @description 后台登录
 */
@Controller
@RequestMapping("admin")
@SessionAttributes({SYS.USER})

public class AdminController {
    //private Jobhunter jobhunter;

    @RequestMapping("/login")
    public String login(Jobhunter jobhunter, Model model) {
        //失败:再次回到登录界面
        //省略了与service、dao调用
        if ("admin".equals(jobhunter.getName()) && "admin".equals(jobhunter.getPass())) {
            model.addAttribute(SYS.USER, jobhunter);
            model.addAttribute(SYS.LOGIN_ERROR, "登錄失敗");
            return "/admin";
        }
        return "/adminLogin";
    }

    //http://localhost:8080/admin/admin
    @RequestMapping("/{jspname}")
    public String show(@PathVariable("jspname") String name) {
        System.out.println("AdminController-show-name=" + name);
        return name;
    }
}
